import request from '@/service/request';
import { DeleteUser, UserPageList, State } from './types';

// 获取到角色分页信息
export function getAllPageUser(data: {
  roleDTO: {
    inputContent: string;
    orderColum: string;
    orderType: string;
    pageNum: number;
    pageSize: number;
    roleList: Array<any>;
    statusList: Array<any>;
  };
}) {
  return request.post<UserPageList[]>({
    url: '/user/getUserList',
    data,
    interceptors: {
      responseInterceptor(res: any): UserPageList[] {
        return res?.data;
      },
    },
  });
}

// 获取到角色分页信息
export function getUserInfoById(data: { id: number }) {
  return request.get<UserPageList[]>({
    url: `/user/${data.id}`,
    data,
    interceptors: {
      responseInterceptor(res: any): UserPageList[] {
        return res?.data;
      },
    },
  });
}

// 添加用户
export function addUser(data: {
  sysUser: {
    name: string;
    sysOrgId: number;
    sysRoleId: number;
    status: number;
    comment: string;
    email: string;
    mobile: string;
    id: number;
  };
}) {
  return request.post<UserPageList[]>({
    url: '/user/editUser',
    data,
    interceptors: {
      responseInterceptor(res: any): UserPageList[] {
        return res;
      },
    },
  });
}

// 删除用户
export function deleteUser(data: { idsids: number }) {
  return request.post<DeleteUser[]>({
    url: '/user/deleteUser',
    data,
    interceptors: {
      responseInterceptor(res: any): DeleteUser[] {
        return res;
      },
    },
  });
}

// 更改用户状态
export function changeState(data: {
  userStatusList: {
    id: number;
    status: number;
  };
}) {
  return request.post<State[]>({
    url: '/user/updateUserStatus',
    data,
    interceptors: {
      responseInterceptor(res: any): State[] {
        return res;
      },
    },
  });
}
